<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录页面</title>
</head>

<body>

  <form action="/verification/login.do" method="POST" id="myForm">
    <label for="">用户名：</label>
    <input type="text" name="username" value="admin">
    <label for="">密码：</label>
    <input type="password" name="password" value="111111">
    <button type="submit">登录</button>
  </form>

  <script>

    document.getElementById('myForm').addEventListener('submit', function (event) {
      event.preventDefault();

      const formData = new FormData(event.target);
      const url = event.target.action;
      const method = event.target.method;

      fetch(url, {
        method: method,
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          username: formData.get('username'),
          password: formData.get('password')
        })
      })
        .then(response => response.json())
        .then(data => {
          console.log('Success:', data);
          window.location.href = './index.html';
        })
        .catch((error) => {
          console.error('Error:', error);
        });
    });

  </script>

</body>

</html>
